/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ekaaty.server.mail.propeties;

import br.com.ekaaty.server.mail.bean.LoginEmail;
import java.util.Properties;
import javax.mail.Session;

/**
 *
 * @author otavio
 */
public abstract class PropretiesGeneric {

    protected LoginEmail login;

    public abstract String getNameServer();

    public abstract String getPorta();

    public abstract LoginEmail getLoginDefault();

    public PropretiesGeneric(LoginEmail login) {
        this.login = login;
    }

    public PropretiesGeneric() {
        this.login = getLoginDefault();

    }

    public Properties getProperties() {
        Properties props = new Properties();
        String mailSMTPServer = getNameServer();
        String mailSMTPServerPort = getPorta();
        Session session = Session.getInstance(props, null);
        props.put("mail.transport.protocol", "smtp"); //define protocolo de envio como SMTP
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", mailSMTPServer); //server SMTP do GMAIL
        props.put("mail.smtp.auth", "true"); //ativa autenticacao
        props.put("mail.smtp.user", login.getLogin()); //usuario ou seja, a conta que esta enviando o email (tem que ser do GMAIL)
        props.put("mail.debug", "true");
        props.put("mail.smtp.port", mailSMTPServerPort); //porta
        props.put("mail.smtp.socketFactory.port", mailSMTPServerPort); //mesma porta para o socket
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");
        return props;
    }

    public LoginEmail getLoginEmail() {
        return login;
    }

    public void setLoginEmail(LoginEmail login) {
        this.login = login;
    }

    
}
